package com.simple.study.service.impl;

import com.simple.study.base.dao.MyMapper;
import com.simple.study.base.service.impl.BaseServiceImpl;
import com.simple.study.mapper.LoginMapper;
import com.simple.study.mapper.UserMapper;
import com.simple.study.pojo.User;
import com.simple.study.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;

/**
 * @ClassName LoginServiceImpl
 * @Author SimpleTree
 **/
@Service
public class LoginServiceImpl extends BaseServiceImpl implements LoginService {


    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public MyMapper getMapper() {
        return loginMapper;
    }

    @Override
    public boolean login(User user) {
        User user1 = new User();
        user1.setUsername(user.getUsername());
        User user2 = loginMapper.selectOne(user1);
        if (null == user2) {
            return false;
        } else {
            return BCrypt.checkpw(user.getPassword(), user2.getPassword());
        }
    }

    /**
     * 返回user信息
     * @param username
     * @return
     */
    @Override
    public User userInfo(String username) {
        return userMapper.selectByUsername(username);
    }
}
